package com.situ.shoplookweb.controller;

import com.situ.shoplook.common.model.GoodsInfo;
import com.situ.shoplook.common.service.GoodsInfoService;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.Map;

/**
 * @Author xinchen
 * @Date: 2024/09/05/ 17:01
 * @Description
 */
@Controller
public class GoodsController {

    @Autowired
    private GoodsInfoService goodsInfoService;


    @GetMapping("/goods/detail/{goodsId}")
    public String detailPage(@PathVariable("goodsId") Long goodsId, HttpServletRequest request) {
        if (goodsId < 1) {
            request.setAttribute("errorMsg", "商品不存在");
            return "error/error_404";
        }
        GoodsInfo goodsInfo = goodsInfoService.getGoodsById(goodsId);
        /**
         * 判断商品是否下架
         */
        if (goodsInfo.getGoodsSellStatus().equals(1)) {
            request.setAttribute("errorMsg", "商品已下架");
            return "error/error_404";
        }
        /**
         * 商品详情图
         */
        request.setAttribute("goodsDetail", goodsInfo);

        return "mall/detail";
    }

}
